package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.common.annotion.log.BussinessLog;
import com.stylefeng.guns.common.constant.Dict;
import com.stylefeng.guns.common.controller.BaseController;
import com.stylefeng.guns.common.persistence.dao.*;
import com.stylefeng.guns.common.persistence.model.CollectComplain;
import com.stylefeng.guns.common.persistence.model.OrgInfo;
import com.stylefeng.guns.common.persistence.model.OrgUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * 用户投诉控制器
 *
 * @author fengshuonan
 * @Date 2018-10-22 09:47:25
 */
@Controller
@RequestMapping("/collectComplain")
public class CollectComplainController extends BaseController {

    private String PREFIX = "/system/collectComplain/";

    @Autowired
    CollectComplainMapper collectComplainMapper;
    @Autowired
    OrgInfoMapper orgInfoMapper;
    @Autowired
    OrgTeacherMapper orgTeacherMapper;
    @Autowired
    OrgClassTypeMapper orgClassTypeMapper;
    @Autowired
    OrgUserMapper orgUserMapper;

    /**
     * 跳转到用户投诉首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "collectComplain.html";
    }

    /**
     * 跳转到添加用户投诉
     */
    @RequestMapping("/collectComplain_add")
    public String collectComplainAdd() {
        return PREFIX + "collectComplain_add.html";
    }

    /**
     * 跳转到修改用户投诉
     */
    @RequestMapping("/collectComplain_update/{collectComplainId}")
    public String collectComplainUpdate(@PathVariable Integer collectComplainId, Model model) {
        return PREFIX + "collectComplain_edit.html";
    }

    /**
     * 获取用户投诉列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        List<CollectComplain> collectComplains = collectComplainMapper.selectList(null);
        for(CollectComplain collectComplain:collectComplains){
            String infoIds = collectComplain.getInfoId();
            String userIds = collectComplain.getUserId();
            OrgUser opUser = orgUserMapper.selectById(userIds);
            OrgInfo orgInfo = orgInfoMapper.selectById(infoIds);
            String infoName = orgInfo.getOrgName();
            String userName = opUser.getUserName();
            collectComplain.setInfoId(infoName);
            collectComplain.setUserId(userName);
        }
        return collectComplains;
    }

    /**
     * 新增用户投诉
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add() {
        return super.SUCCESS_TIP;
    }

    /**
     * 删除用户投诉
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @BussinessLog(value = "删除投诉",key = "collectComplainId",dict = Dict.DeleteDict)
    public Object delete(@RequestParam long collectComplainId) {
        collectComplainMapper.deleteById(collectComplainId);
        return SUCCESS_TIP;
    }


    /**
     * 修改用户投诉
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update() {
        return super.SUCCESS_TIP;
    }

    /**
     * 用户投诉详情
     */
    @RequestMapping(value = "/detail")
    @ResponseBody
    public Object detail() {
        return null;
    }
}
